package com.sysu.simulation;


import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.sysu.simulation.adapter.BaseRecyclerAdapter;
import com.sysu.simulation.adapter.RecordsListAdapter;
import com.sysu.simulation.bean.ListResult;
import com.sysu.simulation.helper.AccountHelper;
import com.sysu.simulation.helper.ApiHelper;
import com.sysu.simulation.helper.NetworkHelper;
import com.sysu.simulation.widget.BaseRecyclerFragment;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import butterknife.BindView;


public class RecordFragment extends BaseRecyclerFragment<String> {

    @Override
    protected void initData() {
        setCache(false);
        super.initData();
    }

    @Override
    protected void requestData() {
        super.requestData();
        if(NetworkHelper.hasInternet(mContext)) {
            ApiHelper.getRecords(AccountHelper.getUserId(), mHandler);
        }
        else {
            Toast.makeText(mContext,"未连接网络",Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    protected Type getResultType() {
        return new TypeToken<ListResult<String>>(){}.getType();
    }

    @Override
    protected Type getCacheType() {
        return new TypeToken<ListResult<String>>(){}.getType();
    }

    @Override
    protected String getCacheKeyName() {
        return null;
    }

    @Override
    protected void onItemClick(String item, int position) {
        Bundle mBundle = new Bundle();
        mBundle.putString("simresult",item);
        RecordChartActivity.show(mContext, mBundle);
    }

    @Override
    protected void onItemLongClick(String item, int position) {

    }

    @Override
    protected BaseRecyclerAdapter<String> getAdapter() {
        return new RecordsListAdapter(mContext);
    }

    @Override
    protected RecyclerView.LayoutManager getLayoutManager() {
        return new LinearLayoutManager(mContext);
    }

}
